<template>
  <div>
    <div class="header-abs"
      @click="handleBackClick"
      v-show="showAbs"
    >
      <span class="iconfont icon-back">&#xe624;</span>
    </div>
    <div class="header-fixed"
      v-show="!showAbs"
      :style="opacityStyle"
    >
      <span class="iconfont header-back" @click="handleBackClick">&#xe624;</span>
      景点详情
    </div>
  </div>
</template>
<script>
export default {
  name: 'DetailHeader',
  data () {
    return {
      showAbs: true,
      opacityStyle: {
        opacity: 0
      }
    }
  },
  methods: {
    handleBackClick () {
      this.$router.go(-1)
    },
    handleScroll () {
      // console.log('scroll')
      let top = document.documentElement.scrollTop
      if (top > 60) {
        if (top < 140) {
          let opacity = top / 140
          this.opacityStyle = {opacity}
        }
        this.showAbs = false
      } else {
        this.showAbs = true
      }
    }
  },
  activated () {
    window.addEventListener('scroll', this.handleScroll)
  },
  // 全局事件进行解绑
  deactivated () {
    window.removeEventListener('scroll', this.handleScroll)
  }
}
</script>
<style lang="stylus" scoped>
  @import '~styles/varibles.styl'
  .header-abs
    position absolute
    left .2rem
    top .2rem
    width .8rem
    height .8rem
    border-radius .4rem
    background-color rgba(0,0,0,.8)
    text-align center
    line-height .8rem
    .icon-back
      color #fff
      font-size .4rem
  .header-fixed
    z-index 2
    position: fixed
    top 0
    left 0
    right 0
    height: .86rem
    line-height: .86rem
    text-align: center
    color: #fff
    background-color: $bgColor
    font-size: .32rem
    .header-back
      position: absolute
      left: 0
      top: 0
      width: .64rem
      text-align: center
      font-size: .4rem
</style>
